removeLinkModuleDescriptor

Has anybody ever tried to delete link module descriptors via DXL?

when I try this code

LinkModuleDescriptor lmd
Folder lmdFolder = getParentFolder(current Module)
 
for lmd in lmdFolder do {
    string src = getSourceName(lmd)
        string tgt = getTargetName(lmd)
        string err = removeLinkModuleDescriptor(lmdFolder, src, tgt) 
        if ( err != "" ) print err ""
}


DOORS always crashed with an EXEPTION_ACCESS_VIOLATION error.

Karl


kabr - Thu Nov 29 03:43:51 EST 2012

Re: removeLinkModuleDescriptor
SystemAdmin - Thu Nov 29 04:20:30 EST 2012

Hi Karl,

haven't evaluated this but it sounds like the usual "never delete something you iterate over".

Make two loops. In the first one (for lmd in lmdFolder) put the lmd in a skip list
in the second one (for lmd in mySkip) delete the lmd.
Cu
Mike

Re: removeLinkModuleDescriptor
kabr - Thu Nov 29 08:13:19 EST 2012

SystemAdmin - Thu Nov 29 04:20:30 EST 2012
Hi Karl,

haven't evaluated this but it sounds like the usual "never delete something you iterate over".

Make two loops. In the first one (for lmd in lmdFolder) put the lmd in a skip list
in the second one (for lmd in mySkip) delete the lmd.
Cu
Mike

Thank you, Mike,

you're perfectly right.
Trying to delete the lmd inside the loop caused the crash.

I really should have known myself actually.

Karl

Re: removeLinkModuleDescriptor
SystemAdmin - Thu Nov 29 13:27:34 EST 2012

kabr - Thu Nov 29 08:13:19 EST 2012
Thank you, Mike,

you're perfectly right.
Trying to delete the lmd inside the loop caused the crash.

I really should have known myself actually.

Karl

string RemoveLinkPairing(Module SourceMod, string TargetORLink, bool flag)
{
    //If flag is false it removes all linking pairing through supplied LINKMODULE
        const Regexp SrcRegx = regexp2 fullName(SourceMod)
        const Regexp TrgRegx = regexp2 TargetORLink     
        int LMDcnt = 0
        
        Folder fol = getParentFolder (SourceMod)
        LinkModuleDescriptor LMD = null
        string ret = null
        Skip skp = create()
        
        for LMD in fol do { 
                string modSource = getSourceName(LMD) 
                string modTarget = getTargetName(LMD)
                string modTargetORlinkmodule = null
                
                if(flag) { modTargetORlinkmodule = getTargetName(LMD) } else { modTargetORlinkmodule = getName(LMD) }
                if((SrcRegx modSource) && (TrgRegx modTargetORlinkmodule)) { put(skp, LMDcnt++, LMD) }
        }
        
        for LMD in skp do {
                string modSource = getSourceName(LMD) 
                string modTarget = getTargetName(LMD)
            ret = removeLinkModuleDescriptor(fol, modSource, modTarget)
        }
        
        delete(skp)
        delete(SrcRegx)
        delete(TrgRegx)
        
        return ((ret!=null)?ret:LMDcnt"")
}
 
string RemoveLinkPairing(Module SourceMod, string TargetORLink) { RemoveLinkPairing(SourceMod, TargetORLink, true) }
 
print RemoveLinkPairing(current Module, "/New Family Car Project/Admin/Satisfies", false)

Re: removeLinkModuleDescriptor
llandale - Thu Nov 29 16:12:19 EST 2012

SystemAdmin - Thu Nov 29 13:27:34 EST 2012

string RemoveLinkPairing(Module SourceMod, string TargetORLink, bool flag)
{
    //If flag is false it removes all linking pairing through supplied LINKMODULE
        const Regexp SrcRegx = regexp2 fullName(SourceMod)
        const Regexp TrgRegx = regexp2 TargetORLink     
        int LMDcnt = 0
        
        Folder fol = getParentFolder (SourceMod)
        LinkModuleDescriptor LMD = null
        string ret = null
        Skip skp = create()
        
        for LMD in fol do { 
                string modSource = getSourceName(LMD) 
                string modTarget = getTargetName(LMD)
                string modTargetORlinkmodule = null
                
                if(flag) { modTargetORlinkmodule = getTargetName(LMD) } else { modTargetORlinkmodule = getName(LMD) }
                if((SrcRegx modSource) && (TrgRegx modTargetORlinkmodule)) { put(skp, LMDcnt++, LMD) }
        }
        
        for LMD in skp do {
                string modSource = getSourceName(LMD) 
                string modTarget = getTargetName(LMD)
            ret = removeLinkModuleDescriptor(fol, modSource, modTarget)
        }
        
        delete(skp)
        delete(SrcRegx)
        delete(TrgRegx)
        
        return ((ret!=null)?ret:LMDcnt"")
}
 
string RemoveLinkPairing(Module SourceMod, string TargetORLink) { RemoveLinkPairing(SourceMod, TargetORLink, true) }
 
print RemoveLinkPairing(current Module, "/New Family Car Project/Admin/Satisfies", false)

This looks pretty good.
  • I don't think you need (or want) the Regexp. getSourceName(lmd) returns a full name and you can compare it directly to fullName(SourceMod). As it is if you want to remove an LMD from a module named "A" you may create a lot of havok if your path contains "A" anywhere.
  • This may relieve callers from worrying about "flag"; adding an "s" to the name:
    • string RemoveLinkPairings(Module SourceMod, string LinkModName) { RemoveLinkPairing(SourceMod, LinkModName, false) }
  • you don't need the first "modTarget".

-Louie

Re: removeLinkModuleDescriptor
SystemAdmin - Fri Nov 30 09:27:53 EST 2012

llandale - Thu Nov 29 16:12:19 EST 2012
This looks pretty good.

  • I don't think you need (or want) the Regexp. getSourceName(lmd) returns a full name and you can compare it directly to fullName(SourceMod). As it is if you want to remove an LMD from a module named "A" you may create a lot of havok if your path contains "A" anywhere.
  • This may relieve callers from worrying about "flag"; adding an "s" to the name:
    • string RemoveLinkPairings(Module SourceMod, string LinkModName) { RemoveLinkPairing(SourceMod, LinkModName, false) }
  • you don't need the first "modTarget".

-Louie

Updates based on comments!!!!

string RemoveLinkPairings(Module SourceMod, string TargetORLink, bool flag)
{
    //If flag is false it removes all linking pairing through supplied LINKMODULE
        int LMDcnt = 0
        
        Folder fol = getParentFolder (SourceMod)
        LinkModuleDescriptor LMD = null
        string ret = null
        Skip skp = create()
        
        for LMD in fol do { 
                string modSource = getSourceName(LMD) 
                string modTargetORlinkmodule = null
                
                if(flag) { modTargetORlinkmodule = getTargetName(LMD) } else { modTargetORlinkmodule = getName(LMD) }
                if((fullName(SourceMod) == modSource) && (TargetORLink == modTargetORlinkmodule)) { put(skp, LMDcnt++, LMD) }
        }
        
        for LMD in skp do {
                string modSource = getSourceName(LMD) 
                string modTarget = getTargetName(LMD)
            ret = removeLinkModuleDescriptor(fol, modSource, modTarget)
        }
        
        delete(skp)
        
        return ((ret!=null)?ret:LMDcnt"")
}
 
string RemoveLinkPairings(Module SourceMod, string TargetORLink) { return RemoveLinkPairings(SourceMod, TargetORLink, true) }
 
print RemoveLinkPairings(current Module, "/New Family Car Project/Admin/Satisfies", false)